<template>
  <div>
    <el-breadcrumb class="breadcrumb-row" separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>公告</el-breadcrumb-item>
      <el-breadcrumb-item>公告页面</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <div id="main" class="echar-row" style="width: 1000px; height: 800px">

        <!-- 使用el-table展示公告数据 -->
        <el-table :data="noticelist" style="width: 100%">
          <!-- 增加序号列 -->
          <el-table-column type="index" label="序号" width="80"></el-table-column>
          <el-table-column label="公告标题" prop="noticeTitle"></el-table-column>
          <el-table-column label="公告内容" prop="noticeContent"></el-table-column>
        </el-table>

      </div>
    </el-card>

    <!-- 编辑公告弹框 -->
    <el-dialog
      title="编辑公告"
      :visible.sync="dialogVisible"
      width="40%"
      @close="resetForm"
    >
      <el-form :model="currentNotice" ref="form" label-width="80px">
        <el-form-item label="公告标题" :rules="[ { required: true, message: '请输入公告标题', trigger: 'blur' } ]">
          <el-input v-model="currentNotice.noticeTitle" placeholder="请输入公告标题"></el-input>
        </el-form-item>

        <el-form-item label="公告内容" :rules="[ { required: true, message: '请输入公告内容', trigger: 'blur' } ]">
          <el-input type="textarea" v-model="currentNotice.noticeContent" placeholder="请输入公告内容" rows="6"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="updateNotice">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getNotice } from '@/request'

export default {
  mounted () {
    this.request()
  },
  data () {
    return {
      noticelist: [],
      dialogVisible: false, // 控制编辑弹框的显示与隐藏
      currentNotice: {} // 当前编辑的公告数据
    }
  },
  methods: {
    async request () {
      try {
        const response = await getNotice()
        this.noticelist = response.data // 假设返回的数据存储在 response.data 中
      } catch (error) {
        console.error('获取公告失败:', error)
      }
    }

  }
}
</script>

<style lang="scss" scoped>
</style>
